﻿using System.Collections.Generic;

namespace IceCS.MovieRent
{
    class Customer
    {
        public string Name { get; private set; }
        private List<Rental> rentals;
        public Customer(string name)
        {
            Name = name;
            rentals = new List<Rental>();
        }
        public void AddRental(Rental rental)
        {
            rentals.Add(rental);
        }

        public string Statement()
        {
            string result = "Rental Record for " + Name + "\n";
            foreach (var rental in rentals)
            {
                result += "\t" + rental.Movie.Title + "\t" + rental.GetCharge() + "\n";
            }
            // add footer lines
            result += "Amount owed is " + GetTotalCharge() + "\n";
            result += "You earned " + GetTotalFrequentRenterPoints() + " frequent renter points";
            return result;
        }

        public string HtmlStatement()
        {
            string result = "<H1>Rentals for <EM>" + Name + "</EM></H1><P>\n";
            foreach (var rental in rentals)
            {
                // show figures for each rental
                result += rental.Movie.Title + ": " + rental.GetCharge() + "<BR>\n";
            }
            // add footer lines
            result += "<P> You owe <EM>" + GetTotalCharge() + "</EM><P>\n";
            result += "On this rental you earned <EM>" + GetTotalFrequentRenterPoints()
                    + "</EM> frequent renter points<P>";
            return result;
        }

        private double GetTotalCharge()
        {
            var total = 0D;
            foreach (var rental in rentals)
            {
                total += rental.GetCharge();
            }
            return total;
        }

        private int GetTotalFrequentRenterPoints()
        {
            var total = 0;
            foreach (var rental in rentals)
            {
                total += rental.GetFrequentRenterPoints();
            }
            return total;
        }

        /// <summary>
        /// can delete if is ok
        /// </summary>
        /// <param name="rental"></param>
        /// <returns></returns>
        private double AmountFor(Rental rental)
        {
            return rental.GetCharge();
        }
    }

}
